import Config from '../config/config.js';

// 声明一个方块类，相当于是构造函数和原型方法的结合
export default class Block{
    // 这个是es6的构造函数
    constructor(opt){
        opt = opt || {};
        this.x = opt.x || 0;
        this.y = opt.y || 0;
        this.width = opt.width || Config.BlockSize;
        this.height = opt.height || Config.BlockSize;
        this.color = opt.color || 'gold';
    }
    // 这里相当于是原型的方法
    init(){        
        this.element = document.createElement('div');
        this.element.style.width = this.width + 'px';
        this.element.style.height = this.height + 'px';        
        this.element.style.position = 'absolute';
        this.element.style.backgroundColor = this.color;
    }
    render(parent){        
        this.element.style.top = this.y + 'px';
        this.element.style.left = this.x + 'px';
        parent.appendChild(this.element);        
    }
    
}